//
//  ScFImagesCell.swift
//  eemall
//
//  Created by zhuxietong on 2018/8/28.
//  Copyright © 2018年 zhuxietong. All rights reserved.
//

import Foundation
import soapp
import Eelay

extension MallForm{
    public class MGoodsUploadCell: FieldCell {
        var field = GImageField()
        let placeHolderL = UILabel()
        override public func addLayoutRules() {
            let t = Int(FieldCell.padding_top)
            //            let b = Int(FieldCell.padding_bottom)
            let l = Int(FieldCell.padding_left)
            let r = Int(FieldCell.padding_right)
            
            contentView.eelay = [
                [titleL,[ee.T.L.R,[t,l,-r]]],
                [field,[ee.L.B,[l,-30]],[titleL,ee.B,ee.T,10]],
            ]
            _ = titleL.ui.font13.text(color: ._foreground)
            weak var wself = self
            field.valueChange = {
                str in
                wself?.active(ID: "updateTable")
            }
        }
        
        override public func mo_model_reload() {
            
            
            titleL.attributedText = mo.model["title",""].ui.font13.color(color: ._foreground).astring + " \(mo.model["mark",""])".ui.font13.cl_888.astring
            field.controller = self.content_controller
            if let f = DataNode<NSMutableDictionary>.path(node: "\(FK.field)", mo.model)
            {
                field.mo.model = f
            }
            else
            {
                if let f = DataNode<NSMutableDictionary>.path(node: "\(FK.fields).0", mo.model)
                {
                    field.mo.model = f
                }
            }
            placeHolderL.text = field.place_holder
        }
        
    }
    
    public class MGoodsUploadCell1: FieldCell {
        
        public var field = GImageField()
        public let placeHolderL = UILabel()
        public override func addLayoutRules() {
            
            //        titleL.ui.font16.cl_666.node("title")
            //        let w = Int(FieldCell.name_width)
            //        let t = Int(FieldCell.padding_top)
            
            //        contentView.eelay = [
            //            [titleL,[ee.T.L,[t,__edge]],"21",.<w],
            //            [requiredMark,[titleL,ee.Y,3],[titleL,ee.R,ee.L,2]],
            //            [placeHolderL,[requiredMark,ee.R,ee.L,3.+1000],[ee.R,.<(-10)],[titleL,ee.Y]],
            //            [__line,[ee.L.R,[__edge,-__edge]],"0.5",[titleL,ee.B,ee.T,t]],
            //        ]
            //        self.indicator = .none
            //
            //        __line.backgroundColor = _separator_color
            //        titleL.setContentConstrainToHighLever()
            //        requiredMark.ui.font18.text("*").text(color: .clear)
            //        rightIcon.ui.font(size: 13).ncolor(hex: "#aaa")
            //        placeHolderL.ui.font13.left.setTextColor(FieldView.holderStyle.color)
            //        placeHolderL.font = FieldView.holderStyle.font
            //        contentView.eelay = [
            //            [field,[ee.B,-10],[__line,ee.B,ee.T,8],[ee.L,20]],
            //        ]
            //
            
            contentView.eelay = [
                [field,[ee.T.L.B,[10,AppTheme.edge,-10]]],
            ]
            
            weak var wself = self
            field.valueChange = {
                str in
                wself?.active(ID: "updateTable")
            }
        }
        
        public override func mo_model_reload() {
            //        contentView.fillData(model: mo.model)
            field.controller = self.content_controller
            
            if let f = DataNode<NSMutableDictionary>.path(node: "\(FK.field)", mo.model)
            {
                field.mo.model = f
            }
            else
            {
                if let f = DataNode<NSMutableDictionary>.path(node: "\(FK.fields).0", mo.model)
                {
                    field.mo.model = f
                }
            }
            placeHolderL.text = field.place_holder
        }
        
        
    }
    
    

}
